/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, Hardware
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "gtest/gtest.h"

#include <cstdio>
#include <cstdlib>
#include <errno.h>
#include <fcntl.h>
#include <fstream>
#include <unistd.h>

#include "hmfs_encoding.h"
#include "hmfs_common.h"
#include "hmfs_test_utils.h"

using namespace testing;
using namespace testing::ext;

namespace OHOS {
namespace Hmfs {
const std::string F2FS_BINARY_PATH = "/system/bin/mkfs.f2fs";
const std::string HMFS_BINARY_PATH = "/system/bin/mkfs.hmfs";

class MkfsHmfsSingleTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp() override;
    void TearDown() override;
    static int32_t ExecutableCmd(const char *path, char *const argv[]);
    static int32_t ExecMkfsBinary(const std::string &fsType, std::vector<std::string>& params,
        const std::string &devPath = nullptr);
    static int32_t ExecDdBinary(const std::string &devPath);
    static bool ExecFsckBinaryAndCkeck(const std::string &devPath);
};

void MkfsHmfsSingleTest::SetUpTestCase() {}
void MkfsHmfsSingleTest::TearDownTestCase() {}
void MkfsHmfsSingleTest::SetUp()
{
    std::vector<char*> f2fsArgv;
    f2fsArgv.emplace_back(const_cast<char*>("/system/bin/dd"));
    f2fsArgv.emplace_back(const_cast<char*>("if=/dev/zero"));
    f2fsArgv.emplace_back(const_cast<char*>("of=/data/f2fsTest"));
    f2fsArgv.emplace_back(const_cast<char*>("bs=1M"));
    f2fsArgv.emplace_back(const_cast<char*>("count=100"));
    f2fsArgv.emplace_back(nullptr);
    int32_t res = MkfsHmfsSingleTest::ExecutableCmd(f2fsArgv[0], f2fsArgv.data());

    std::cout << "MkfsHmfsSingleTest::SetUp res = " << res << std::endl;
    std::vector<char*> hmfsArgv;
    hmfsArgv.emplace_back(const_cast<char*>("/system/bin/dd"));
    hmfsArgv.emplace_back(const_cast<char*>("if=/dev/zero"));
    hmfsArgv.emplace_back(const_cast<char*>("of=/data/hmfsTest"));
    hmfsArgv.emplace_back(const_cast<char*>("bs=1M"));
    hmfsArgv.emplace_back(const_cast<char*>("count=100"));
    hmfsArgv.emplace_back(nullptr);
    MkfsHmfsSingleTest::ExecutableCmd(hmfsArgv[0], hmfsArgv.data());


}

void MkfsHmfsSingleTest::TearDown()
{
    std::vector<char*> f2fsArgv;
    f2fsArgv.emplace_back(const_cast<char*>("/bin/sh"));
    f2fsArgv.emplace_back(const_cast<char*>("-c"));
    f2fsArgv.emplace_back(const_cast<char*>("rm -rf /data/f2fsTest*"));
    f2fsArgv.emplace_back(nullptr);
    MkfsHmfsSingleTest::ExecutableCmd(f2fsArgv[0], f2fsArgv.data());
    std::vector<char*> hmfsArgv;
    hmfsArgv.emplace_back(const_cast<char*>("/bin/sh"));
    hmfsArgv.emplace_back(const_cast<char*>("-c"));
    hmfsArgv.emplace_back(const_cast<char*>("rm -rf /data/hmfsTest*"));
    hmfsArgv.emplace_back(nullptr);
    MkfsHmfsSingleTest::ExecutableCmd(hmfsArgv[0], hmfsArgv.data());
}

int32_t MkfsHmfsSingleTest::ExecutableCmd(const char *path, char *const argv[])
{
    if (path == nullptr || argv == nullptr ) {
        return -1;
    }

    pid_t pid = fork();
    if (pid < 0) {
        return -errno;
    }

    if (pid == 0) {
        if (execv(path, argv) == -1) {
            _exit(EXIT_FAILURE);
        }
    }

    int status = -1;
    pid_t wpid = waitpid(pid, &status, 0);
    if (wpid == -1) {
        return -errno;
    }

    if (WIFEXITED(status)) {
        return WEXITSTATUS(status);
    }
    return -ECHILD;
}

int32_t MkfsHmfsSingleTest::ExecDdBinary(const std::string &devPath)
{
    if (devPath.empty()) {
        std::cout<<"ExecDdBinary Invalid param"<<std::endl;
        return -1;
    }
    pid_t pid = fork();
    if (pid < 0) {
        return -errno;
    }

    std::string str = "of=" + devPath;
    if (pid == 0) {
        std::vector<char*> argv;
        argv.emplace_back(const_cast<char*>("/system/bin/dd"));
        argv.emplace_back(const_cast<char*>("if=/dev/zero"));
        argv.emplace_back(const_cast<char*>(str.c_str()));
        argv.emplace_back(const_cast<char*>("bs=1M"));
        argv.emplace_back(const_cast<char*>("count=100"));
        argv.emplace_back(nullptr);
        if (execv(argv[0], argv.data()) == -1) {
            _exit(EXIT_FAILURE);
        }
    }

    int status = -1;
    pid_t wpid = waitpid(pid, &status, 0);
    if (wpid == -1) {
        return -errno;
    }

    if (WIFEXITED(status)) {
        return WEXITSTATUS(status);
    }
    return -ECHILD;
}

int32_t MkfsHmfsSingleTest::ExecMkfsBinary(const std::string &fsType, std::vector<std::string>& params,
    const std::string &devPath)
{
    pid_t pid = fork();
    if (pid < 0) {
        return -errno;
    }

    if (pid == 0) {
        std::vector<char*> argv;
        if (fsType == "f2fs") {
            argv.emplace_back(const_cast<char*>(F2FS_BINARY_PATH.c_str()));
        }
        if (fsType == "hmfs") {
            argv.emplace_back(const_cast<char*>(HMFS_BINARY_PATH.c_str()));
        }
        for (const auto &param : params) {
            argv.emplace_back(const_cast<char*>(param.c_str()));
        }
        argv.emplace_back(const_cast<char*>(devPath.c_str()));
        argv.emplace_back(nullptr);
        if (execv(argv[0], argv.data()) == -1) {
            _exit(EXIT_FAILURE);
        }
    }

    int status = -1;
    pid_t wpid = waitpid(pid, &status, 0);
    if (wpid == -1) {
        return -errno;
    }

    if (WIFEXITED(status)) {
        return WEXITSTATUS(status);
    }
    return -ECHILD;
}

bool MkfsHmfsSingleTest::ExecFsckBinaryAndCkeck(const std::string &devPath)
{
    std::string outputFile = "/data/local/fsck.txt";
    std::vector<std::string> argv;
    argv.push_back("/system/bin/fsck.f2fs");
    argv.push_back(devPath);

    ExecutableCmdWithOutput(argv, outputFile);
    return PrintFsckErrorMsg(outputFile,devPath);
}
/*
 * @tc.name: MkfsHmfsTest_001
 * @tc.desc: test for no parameter
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_no_param_001, TestSize.Level1)
{
    std::vector<std::string> params;
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", f2fsCkeckPoint);

    params.clear();
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);

    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", hmfsCkeckPoint);

    SuperBlockCode sbRet = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    EXPECT_EQ(SUCCESSED_SB, sbRet);
    CheckPointCode cpRet = CompareCheckPoint(f2fsCkeckPoint, hmfsCkeckPoint);
    EXPECT_EQ(SUCCESSED_CP, cpRet);
}

/*
 * @tc.name: MkfsHmfsTest_a_001
 * @tc.desc: test for parameter a
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_a_001, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-a 1");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", f2fsCkeckPoint);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", hmfsCkeckPoint);

    EXPECT_EQ(f2fsCkeckPoint->curNodeSegNo[0], hmfsCkeckPoint->curNodeSegNo[0]);
    EXPECT_EQ(f2fsCkeckPoint->curNodeSegNo[1], hmfsCkeckPoint->curNodeSegNo[1]);
    EXPECT_EQ(f2fsCkeckPoint->curNodeSegNo[2], hmfsCkeckPoint->curNodeSegNo[2]);
    EXPECT_EQ(f2fsCkeckPoint->curDataSegNo[0], hmfsCkeckPoint->curDataSegNo[0]);
    EXPECT_EQ(f2fsCkeckPoint->curDataSegNo[1], hmfsCkeckPoint->curDataSegNo[1]);
    EXPECT_EQ(f2fsCkeckPoint->curDataSegNo[2], hmfsCkeckPoint->curDataSegNo[2]);
}

/*
 * @tc.name: MkfsHmfsTest_a_002
 * @tc.desc: test for parameter a
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_a_002, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-a 0");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", f2fsCkeckPoint);


    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", hmfsCkeckPoint);

    EXPECT_EQ(f2fsCkeckPoint->curNodeSegNo[0], hmfsCkeckPoint->curNodeSegNo[0]);
    EXPECT_EQ(f2fsCkeckPoint->curNodeSegNo[1], hmfsCkeckPoint->curNodeSegNo[1]);
    EXPECT_EQ(f2fsCkeckPoint->curNodeSegNo[2], hmfsCkeckPoint->curNodeSegNo[2]);
    EXPECT_EQ(f2fsCkeckPoint->curDataSegNo[0], hmfsCkeckPoint->curDataSegNo[0]);
    EXPECT_EQ(f2fsCkeckPoint->curDataSegNo[1], hmfsCkeckPoint->curDataSegNo[1]);
    EXPECT_EQ(f2fsCkeckPoint->curDataSegNo[2], hmfsCkeckPoint->curDataSegNo[2]);
}

/*
 * @tc.name: MkfsHmfsTest_c_001
 * @tc.desc: test for parameter c
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_c_001, TestSize.Level1)
{
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest1"));
    std::vector<std::string> params;
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest1");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", f2fsCkeckPoint);

    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest1"));
    params.clear();
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest1");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/hmfsTest", hmfsCkeckPoint);

    EXPECT_EQ(f2fsSuperBlock->blockCount, hmfsSuperBlock->blockCount);
    EXPECT_EQ(f2fsSuperBlock->sectionCount, hmfsSuperBlock->sectionCount);
    EXPECT_EQ(f2fsSuperBlock->segmentCount, hmfsSuperBlock->segmentCount);
    EXPECT_EQ(f2fsSuperBlock->segmentCountInMain, hmfsSuperBlock->segmentCountInMain);
    EXPECT_EQ(f2fsCkeckPoint->userBlockCount, hmfsCkeckPoint->userBlockCount);
    EXPECT_EQ(f2fsCkeckPoint->validBlockCount, hmfsCkeckPoint->validBlockCount);
    EXPECT_EQ(f2fsCkeckPoint->rsvdSegmentCount, hmfsCkeckPoint->rsvdSegmentCount);
    EXPECT_EQ(f2fsCkeckPoint->overprovSegmentCount, hmfsCkeckPoint->overprovSegmentCount);
    EXPECT_EQ(f2fsCkeckPoint->freeSegmentCount, hmfsCkeckPoint->freeSegmentCount);

    SuperBlockCode sbRet = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    EXPECT_EQ(SUCCESSED_SB, sbRet);
    CheckPointCode cpRet = CompareCheckPoint(f2fsCkeckPoint, hmfsCkeckPoint);
    EXPECT_EQ(SUCCESSED_CP, cpRet);
}

/*
 * @tc.name: MkfsHmfsTest_c_002
 * @tc.desc: test for parameter c
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_c_002, TestSize.Level1)
{
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest1"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest2"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest3"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest4"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest5"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest6"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest7"));
    std::vector<std::string> params;
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest1");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest2");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest3");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest4");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest5");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest6");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest7");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", f2fsCkeckPoint);

    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest1"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest2"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest3"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest4"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest5"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest6"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest7"));
    params.clear();
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest1");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest2");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest3");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest4");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest5");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest6");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest7");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/hmfsTest", hmfsCkeckPoint);

    SuperBlockCode sbRet = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    EXPECT_EQ(SUCCESSED_SB, sbRet);
    CheckPointCode cpRet = CompareCheckPoint(f2fsCkeckPoint, hmfsCkeckPoint);
    EXPECT_EQ(SUCCESSED_CP, cpRet);
}

/*
 * @tc.name: MkfsHmfsTest_c_003
 * @tc.desc: test for parameter c,
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_c_003, TestSize.Level1)
{
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest1"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest2"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest3"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest4"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest5"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest6"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest7"));
    EXPECT_EQ(0, ExecDdBinary("/data/f2fsTest8"));
    std::vector<std::string> params;
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest1");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest2");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest3");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest4");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest5");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest6");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest7");
    params.emplace_back("-c");
    params.emplace_back("/data/f2fsTest8");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest1"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest2"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest3"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest4"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest5"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest6"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest7"));
    EXPECT_EQ(0, ExecDdBinary("/data/hmfsTest8"));
    params.clear();
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest1");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest2");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest3");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest4");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest5");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest6");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest7");
    params.emplace_back("-c");
    params.emplace_back("/data/hmfsTest8");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
}

/*
 * @tc.name: MkfsHmfsTest_c_004
 * @tc.desc: test for parameter c
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_c_004, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-c /data/xxxxxxxxx/xxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxx/hmfsTest1");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
}

/*
 * @tc.name: MkfsHmfsTest_e_001
 * @tc.desc: test for parameter e
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_e_001, TestSize.Level1)
{
    std::vector<std::string> params;
    std::string fileSuffix = "cold";
    params.emplace_back("-e");
    params.emplace_back(fileSuffix);
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);

    EXPECT_EQ(f2fsSuperBlock->coldExtensionCount, hmfsSuperBlock->coldExtensionCount);
    bool flag = false;

    for(int32_t i = 0; i < EXTENSION_COUNT_MAX; i++) {
        EXPECT_STREQ(reinterpret_cast<const char*>(f2fsSuperBlock->extensionList[i]),
            reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]));
        if (strcmp(reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]), fileSuffix.c_str()) == 0) {
            flag = true;
        }
    }
    EXPECT_TRUE(flag);
}

/*
 * @tc.name: MkfsHmfsTest_e_002
 * @tc.desc: test for parameter e, fileSuffix length is 7
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_e_002, TestSize.Level1)
{
    std::vector<std::string> params;
    std::string fileSuffix = "xxxxxxx";
    params.emplace_back("-e");
    params.emplace_back(fileSuffix);
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);

    EXPECT_EQ(f2fsSuperBlock->coldExtensionCount, hmfsSuperBlock->coldExtensionCount);
    bool flag = false;

    for(int32_t i = 0; i < EXTENSION_COUNT_MAX; i++) {
        EXPECT_STREQ(reinterpret_cast<const char*>(f2fsSuperBlock->extensionList[i]),
            reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]));
        if (strcmp(reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]), fileSuffix.c_str()) == 0) {
            flag = true;
        }
    }
    EXPECT_TRUE(flag);
}

/*
 * @tc.name: MkfsHmfsTest_e_003
 * @tc.desc: test for parameter e, fileSuffix length is 8
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_e_003, TestSize.Level1)
{
    std::vector<std::string> params;
    std::string fileSuffix = "xxxxxxxx";
    params.emplace_back("-e");
    params.emplace_back(fileSuffix);
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);

    EXPECT_EQ(f2fsSuperBlock->coldExtensionCount, hmfsSuperBlock->coldExtensionCount);
    bool flag = false;

    for(int32_t i = 0; i < EXTENSION_COUNT_MAX; i++) {
        EXPECT_STREQ(reinterpret_cast<const char*>(f2fsSuperBlock->extensionList[i]),
            reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]));
        if (strcmp(reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]), fileSuffix.c_str()) == 0) {
            flag = true;
        }
    }
    EXPECT_FALSE(flag);
}

/*
 * @tc.name: MkfsHmfsTest_E_001
 * @tc.desc: test for parameter E
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_E_001, TestSize.Level1)
{
    std::vector<std::string> params;
    std::string fileSuffix = "hot";
    params.emplace_back("-E");
    params.emplace_back(fileSuffix);
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);

    EXPECT_EQ(f2fsSuperBlock->hotExtensionCount, hmfsSuperBlock->hotExtensionCount);
    EXPECT_EQ(f2fsSuperBlock->coldExtensionCount, hmfsSuperBlock->coldExtensionCount);
    bool flag = false;

    for(int32_t i = 0; i < EXTENSION_COUNT_MAX; i++) {
        EXPECT_STREQ(reinterpret_cast<const char*>(f2fsSuperBlock->extensionList[i]),
            reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]));
        if (strcmp(reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]), fileSuffix.c_str()) == 0) {
            flag = true;
        }
    }
    EXPECT_TRUE(flag);
}

/*
 * @tc.name: MkfsHmfsTest_E_002
 * @tc.desc: test for parameter E, fileSuffix length is 7
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_E_002, TestSize.Level1)
{
    std::vector<std::string> params;
    std::string fileSuffix = "hhhhhhh";
    params.emplace_back("-E");
    params.emplace_back(fileSuffix);
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);

    EXPECT_EQ(f2fsSuperBlock->hotExtensionCount, hmfsSuperBlock->hotExtensionCount);
    EXPECT_EQ(f2fsSuperBlock->coldExtensionCount, hmfsSuperBlock->coldExtensionCount);
    bool flag = false;

    for(int32_t i = 0; i < EXTENSION_COUNT_MAX; i++) {
        EXPECT_STREQ(reinterpret_cast<const char*>(f2fsSuperBlock->extensionList[i]),
            reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]));
        if (strcmp(reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]), fileSuffix.c_str()) == 0) {
            flag = true;
        }
    }
    EXPECT_TRUE(flag);
}

/*
 * @tc.name: MkfsHmfsTest_E_003
 * @tc.desc: test for parameter E, fileSuffix length is 8
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_E_003, TestSize.Level1)
{
    std::vector<std::string> params;
    std::string fileSuffix = "hhhhhhhh";
    params.emplace_back("-E");
    params.emplace_back(fileSuffix);
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);

    EXPECT_EQ(f2fsSuperBlock->hotExtensionCount, hmfsSuperBlock->hotExtensionCount);
    EXPECT_EQ(f2fsSuperBlock->coldExtensionCount, hmfsSuperBlock->coldExtensionCount);
    bool flag = false;

    for(int32_t i = 0; i < EXTENSION_COUNT_MAX; i++) {
        EXPECT_STREQ(reinterpret_cast<const char*>(f2fsSuperBlock->extensionList[i]),
            reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]));
        if (strcmp(reinterpret_cast<const char*>(hmfsSuperBlock->extensionList[i]), fileSuffix.c_str()) == 0) {
            flag = true;
        }
    }
    EXPECT_FALSE(flag);
}
/*
 * @tc.name: MkfsHmfsTest_f_001
 * @tc.desc: test for parameter f
 * @tc.type: FUNC
 */
// HWTEST_F(MkfsHmfsSingleTest, Test_param_f_001, TestSize.Level1)
// {
//     std::vector<std::string> params;
//     params.emplace_back("-f");
//     params.emplace_back("/data/f2fsTest");
//     EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary(params));

//     params.clear();
//     params.emplace_back("-f");
//     params.emplace_back("/data/hmfsTest");
//     EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary(params));
// }

/*
 * @tc.name: MkfsHmfsTest_g_001
 * @tc.desc: test for parameter g
 * @tc.type: FUNC
 */
// HWTEST_F(MkfsHmfsSingleTest, Test_param_g_001, TestSize.Level1)
// {
//     std::vector<std::string> params;
//     params.emplace_back("-g android");
//     params.emplace_back("/data/f2fsTest");
//     EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary(params));

//     params.clear();
//     params.emplace_back("-g android");
//     params.emplace_back("/data/hmfsTest");
//     EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary(params));

// }


/*
 * @tc.name: MkfsHmfsTest_i_001
 * @tc.desc: test for parameter i
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_i_001, TestSize.Level1) //设置使能，不设不使能
{
    std::vector<std::string> params;
    params.emplace_back("-i");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", f2fsCkeckPoint);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);

    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", hmfsCkeckPoint);

    EXPECT_EQ(f2fsSuperBlock->cpPayload, hmfsSuperBlock->cpPayload);
    EXPECT_EQ(f2fsSuperBlock->segmentCountInNAT, hmfsSuperBlock->segmentCountInNAT);
    EXPECT_EQ(f2fsCkeckPoint->cpFlags, hmfsCkeckPoint->cpFlags);
    EXPECT_EQ(f2fsCkeckPoint->checksumOffset, hmfsCkeckPoint->checksumOffset);
}

/*
 * @tc.name: MkfsHmfsTest_l_001
 * @tc.desc: test for parameter l
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_l_001, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-l MyVolume");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    char f2fsVolumeName[MAX_VOLUME_NAME];
    int ret = Utf16Toutf8(f2fsVolumeName,
        f2fsSuperBlock->volumeName, MAX_VOLUME_NAME, MAX_VOLUME_NAME);
    EXPECT_EQ(ret, 0);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    char hmfsVolumeName[MAX_VOLUME_NAME];
    ret = Utf16Toutf8(hmfsVolumeName,
        hmfsSuperBlock->volumeName, MAX_VOLUME_NAME, MAX_VOLUME_NAME);
    EXPECT_EQ(ret, 0);
    EXPECT_STREQ(f2fsVolumeName, hmfsVolumeName);
}

/*
 * @tc.name: MkfsHmfsTest_m_001
 * @tc.desc: test for parameter m
 * @tc.type: FUNC
 */
// HWTEST_F(MkfsHmfsSingleTest, Test_param_m_001, TestSize.Level1)
// {
//     std::vector<std::string> params;
//     params.emplace_back("-m");
//     EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));
//     EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
// }

/*
 * @tc.name: MkfsHmfsTest_o_001
 * @tc.desc: test for parameter o, the value is 10
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_o_001, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-o 10");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", f2fsCkeckPoint);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", hmfsCkeckPoint);

    EXPECT_EQ(f2fsCkeckPoint->overprovSegmentCount, hmfsCkeckPoint->overprovSegmentCount);
    EXPECT_EQ(f2fsCkeckPoint->rsvdSegmentCount, hmfsCkeckPoint->rsvdSegmentCount);
}

/*
 * @tc.name: MkfsHmfsTest_o_002
 * @tc.desc: test for parameter o, the value is 99.99
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_o_002, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-o 99.99");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", f2fsCkeckPoint);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", hmfsCkeckPoint);

    EXPECT_EQ(f2fsCkeckPoint->overprovSegmentCount, hmfsCkeckPoint->overprovSegmentCount);
    EXPECT_EQ(f2fsCkeckPoint->rsvdSegmentCount, hmfsCkeckPoint->rsvdSegmentCount);
}

/*
 * @tc.name: MkfsHmfsTest_o_003
 * @tc.desc: test for parameter o, the value is 100
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_o_003, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-o 100");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
}

/*
 * @tc.name: MkfsHmfsTest_O_000
 * @tc.desc: test for parameter "-O encrypt"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_000, TestSize.Level1)
{
    std::vector<std::string> params;
    params.clear();
    params.emplace_back("-O encrypt");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_ENCRYPT);
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
}

/*
 * @tc.name: MkfsHmfsTest_O_001
 * @tc.desc: test for parameter "-O extra_attr"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_001, TestSize.Level1)
{
    std::vector<std::string> params;
    params.clear();
    params.emplace_back("-O extra_attr");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_EXTRA_ATTR);
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
}

/*
 * @tc.name: MkfsHmfsTest_O_002
 * @tc.desc: test for parameter "-O extra_attr,project_quota"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_002, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-O project_quota");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));

    params.clear();
    params.emplace_back("-O extra_attr,project_quota");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo("/data/f2fsTest", f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo("/data/hmfsTest", hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    EXPECT_TRUE(hmfsSuperBlock->features & (HMFS_FEATURE_EXTRA_ATTR|HMFS_FEATURE_PRJQUOTA));
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
    EXPECT_EQ(f2fsNodeData->i.iProjid, hmfsNodeData->i.iProjid);
}

/*
 * @tc.name: MkfsHmfsTest_O_003
 * @tc.desc: test for parameter "-O extra_attr,inode_checksum"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_003, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-O inode_checksum");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));

    params.clear();
    params.emplace_back("-O extra_attr,inode_checksum");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo("/data/f2fsTest", f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo("/data/hmfsTest", hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    EXPECT_TRUE(hmfsSuperBlock->features & (HMFS_FEATURE_EXTRA_ATTR|HMFS_FEATURE_INODE_CHKSUM));
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
    EXPECT_NE(0, hmfsNodeData->i.iInodeChecksum);
}

/*
 * @tc.name: MkfsHmfsTest_O_004
 * @tc.desc: test for parameter "-O extra_attr,flexible_inline_xattr"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_004, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-O flexible_inline_xattr");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));

    params.clear();
    params.emplace_back("-O extra_attr,flexible_inline_xattr");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo("/data/f2fsTest", f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo("/data/hmfsTest", hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    EXPECT_TRUE(hmfsSuperBlock->features & (HMFS_FEATURE_EXTRA_ATTR|HMFS_FEATURE_FLEXIBLE_INLINE_XATTR));
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
    EXPECT_EQ(f2fsNodeData->i.iInlineXattrSize, hmfsNodeData->i.iInlineXattrSize);
}

/*
 * @tc.name: MkfsHmfsTest_O_005
 * @tc.desc: test for parameter "-O quota"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_005, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-O quota");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_QUOTA_INO);
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
}

/*
 * @tc.name: MkfsHmfsTest_O_006
 * @tc.desc: test for parameter "-O extra_attr,inode_crtime"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_006, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-O inode_crtime");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));

    params.clear();
    params.emplace_back("-O extra_attr,inode_crtime");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo("/data/f2fsTest", f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo("/data/hmfsTest", hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    EXPECT_TRUE(hmfsSuperBlock->features & (HMFS_FEATURE_EXTRA_ATTR|HMFS_FEATURE_INODE_CRTIME));
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
    EXPECT_NE(hmfsNodeData->i.iCrtime, 0);
}

/*
 * @tc.name: MkfsHmfsTest_O_007
 * @tc.desc: test for parameter "-O lost_found"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_007, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-O lost_found");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_LOST_FOUND);
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
}

/*
 * @tc.name: MkfsHmfsTest_O_008
 * @tc.desc: test for parameter "-O verity"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_008, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-O verity");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_VERITY);
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
}

/*
 * @tc.name: MkfsHmfsTest_O_009
 * @tc.desc: test for parameter "-O sb_checksum"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_009, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-O sb_checksum");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_SB_CHKSUM);
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
}

/*
 * @tc.name: MkfsHmfsTest_O_010
 * @tc.desc: test for parameter "-O casefold"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_010, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-O casefold");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_CASEFOLD);
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
}

/*
 * @tc.name: MkfsHmfsTest_O_011
 * @tc.desc: test for parameter "-O extra_attr,compression"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_011, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-O compression");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));

    params.clear();
    params.emplace_back("-O extra_attr,compression");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo("/data/f2fsTest", f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo("/data/hmfsTest", hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    EXPECT_TRUE(hmfsSuperBlock->features & (HMFS_FEATURE_EXTRA_ATTR|HMFS_FEATURE_COMPRESSION));
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
    EXPECT_EQ(f2fsNodeData->i.iComprBlocks, hmfsNodeData->i.iComprBlocks);
    EXPECT_EQ(f2fsNodeData->i.iCompressAlgrithm, hmfsNodeData->i.iCompressAlgrithm);
    EXPECT_EQ(f2fsNodeData->i.iLogClusterSize, hmfsNodeData->i.iLogClusterSize);
    EXPECT_EQ(f2fsNodeData->i.iPadding, hmfsNodeData->i.iPadding);
}

/*
 * @tc.name: MkfsHmfsTest_O_012
 * @tc.desc: test for parameter "-O ro"
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_O_012, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-O ro");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_RO);
    EXPECT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);

    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint("/data/f2fsTest", hmfsCkeckPoint);

    EXPECT_EQ(hmfsCkeckPoint->curNodeSegNo[1], 0);
    EXPECT_EQ(hmfsCkeckPoint->curNodeSegNo[2], 0);
    EXPECT_EQ(hmfsCkeckPoint->curDataSegNo[0], 0);
    EXPECT_EQ(hmfsCkeckPoint->curDataSegNo[1], 0);
    EXPECT_EQ(hmfsCkeckPoint->curDataSegNo[2], 0);
}

/*
 * @tc.name: MkfsHmfsTest_C_001
 * @tc.desc: test for parameter C
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_C_001, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-C");
    params.emplace_back("utf8");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_EQ(f2fsSuperBlock->encoding, hmfsSuperBlock->encoding);
    EXPECT_EQ(f2fsSuperBlock->encodingFlags, hmfsSuperBlock->encodingFlags);
}

/*
 * @tc.name: MkfsHmfsTest_C_002
 * @tc.desc: test for parameter C
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_C_002, TestSize.Level1)
{
    std::vector<std::string> params;
    params.clear();
    params.emplace_back("-C gbk");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
}

/*
 * @tc.name: MkfsHmfsTest_C_003
 * @tc.desc: test for parameter C
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_C_003, TestSize.Level1)
{
    char name[] = LPF_STRING;
    int len = strlen(LPF_STRING);

    bool flag = IsNeedEncoding(1);
    EXPECT_TRUE(flag);
    auto buff = std::make_unique<unsigned char[]>(HMFS_NAME_LEN);
    int32_t dlen = CaseFold((const unsigned char *)name, len, buff.get(), HMFS_NAME_LEN);
    EXPECT_TRUE(memcmp(buff.get(), LPF_STRING, dlen) == 0);
}
/*
 * @tc.name: MkfsHmfsTest_r_001
 * @tc.desc: test for parameter r
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_r_001, TestSize.Level1) //随机值不可判断
{
    std::vector<std::string> params;
    params.emplace_back("-r");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);
}

/*
 * @tc.name: MkfsHmfsTest_R_001
 * @tc.desc: test for parameter R
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_R_001, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-R 0:0");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo("/data/f2fsTest", f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo("/data/hmfsTest", hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    EXPECT_EQ(f2fsNodeData->i.iUid, hmfsNodeData->i.iUid);
    EXPECT_EQ(f2fsNodeData->i.iGid, hmfsNodeData->i.iGid);
    EXPECT_EQ(hmfsNodeData->i.iGid, 0);
    EXPECT_EQ(hmfsNodeData->i.iGid, 0);
}

/*
 * @tc.name: MkfsHmfsTest_R_002
 * @tc.desc: test for parameter R
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_R_002, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-R 1000:1000");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo("/data/f2fsTest", f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo("/data/hmfsTest", hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    EXPECT_EQ(f2fsNodeData->i.iUid, hmfsNodeData->i.iUid);
    EXPECT_EQ(f2fsNodeData->i.iGid, hmfsNodeData->i.iGid);
    EXPECT_EQ(hmfsNodeData->i.iGid, 1000);
    EXPECT_EQ(hmfsNodeData->i.iGid, 1000);
}
/*
 * @tc.name: MkfsHmfsTest_R_003
 * @tc.desc: test for parameter R
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_R_003, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-R -1000:-1000");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo("/data/f2fsTest", f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo("/data/hmfsTest", hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    EXPECT_EQ(f2fsNodeData->i.iUid, hmfsNodeData->i.iUid);
    EXPECT_EQ(f2fsNodeData->i.iGid, hmfsNodeData->i.iGid);
    uint32_t res = -1000;
    EXPECT_EQ(hmfsNodeData->i.iGid, res);
    EXPECT_EQ(hmfsNodeData->i.iGid, res);
}

/*
 * @tc.name: MkfsHmfsTest_s_001
 * @tc.desc: test for parameter s
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_s_001, TestSize.Level1)
{
    std::vector<std::string> params;
    params.clear();
    params.emplace_back("-s 0");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
}

/*
 * @tc.name: MkfsHmfsTest_s_002
 * @tc.desc: test for parameter s
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_s_002, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-s 2");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);

    EXPECT_EQ(f2fsSuperBlock->segsPerSection, hmfsSuperBlock->segsPerSection);
    EXPECT_EQ(f2fsSuperBlock->segmentCountInMain, hmfsSuperBlock->segmentCountInMain);
    EXPECT_EQ(f2fsSuperBlock->sectionCount, hmfsSuperBlock->sectionCount);
    EXPECT_TRUE(hmfsSuperBlock->segsPerSection == 2);
    EXPECT_TRUE(hmfsSuperBlock->sectionCount > 10);
}

/*
 * @tc.name: MkfsHmfsTest_s_003
 * @tc.desc: test for parameter s
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_s_003, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-s 3");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
}

/*
 * @tc.name: MkfsHmfsTest_s_004
 * @tc.desc: test for parameter s
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_s_004, TestSize.Level1)
{
    std::vector<std::string> params;
    params.clear();
    params.emplace_back("-s 1");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    EXPECT_TRUE(f2fsSuperBlock->segsPerSection == 1);
    EXPECT_TRUE(f2fsSuperBlock->sectionCount > 10);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->segsPerSection == 1);
    EXPECT_TRUE(hmfsSuperBlock->sectionCount > 10);

    EXPECT_EQ(f2fsSuperBlock->segsPerSection, hmfsSuperBlock->segsPerSection);
    EXPECT_EQ(f2fsSuperBlock->segmentCountInMain, hmfsSuperBlock->segmentCountInMain);
    EXPECT_EQ(f2fsSuperBlock->sectionCount, hmfsSuperBlock->sectionCount);
}

/*
 * @tc.name: MkfsHmfsTest_S_001
 * @tc.desc: test for parameter S
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_S_001, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-S");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
}

/*
 * @tc.name: MkfsHmfsTest_t_001
 * @tc.desc: test for parameter t
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test001, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-t 0");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);
}

/*
 * @tc.name: MkfsHmfsTest_t_002
 * @tc.desc: test for parameter t
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test002, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-t 1");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);
}

/*
 * @tc.name: MkfsHmfsTest_T_001
 * @tc.desc: test for parameter T
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_T_001, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-T -1000");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo("/data/f2fsTest", f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo("/data/hmfsTest", hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    EXPECT_EQ(f2fsNodeData->i.iAtime, hmfsNodeData->i.iAtime);
    EXPECT_EQ(f2fsNodeData->i.iAtimeNsec, hmfsNodeData->i.iAtimeNsec);
    EXPECT_EQ(f2fsNodeData->i.iCtime, hmfsNodeData->i.iCtime);
    EXPECT_EQ(f2fsNodeData->i.iCtimeNsec, hmfsNodeData->i.iCtimeNsec);
    EXPECT_EQ(f2fsNodeData->i.iMtime, hmfsNodeData->i.iMtime);
    EXPECT_EQ(f2fsNodeData->i.iMtimeNsec, hmfsNodeData->i.iMtimeNsec);
    uint32_t res = -1000;
    EXPECT_EQ(hmfsNodeData->i.iAtime, res);
    EXPECT_EQ(hmfsNodeData->i.iCtime, res);
    EXPECT_EQ(hmfsNodeData->i.iMtime, res);
}

/*
 * @tc.name: MkfsHmfsTest_T_002
 * @tc.desc: test for parameter T
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_T_002, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-T 1731565670");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo("/data/f2fsTest", f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo("/data/hmfsTest", hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    EXPECT_EQ(f2fsNodeData->i.iAtime, hmfsNodeData->i.iAtime);
    EXPECT_EQ(f2fsNodeData->i.iAtimeNsec, hmfsNodeData->i.iAtimeNsec);
    EXPECT_EQ(f2fsNodeData->i.iCtime, hmfsNodeData->i.iCtime);
    EXPECT_EQ(f2fsNodeData->i.iCtimeNsec, hmfsNodeData->i.iCtimeNsec);
    EXPECT_EQ(f2fsNodeData->i.iMtime, hmfsNodeData->i.iMtime);
    EXPECT_EQ(f2fsNodeData->i.iMtimeNsec, hmfsNodeData->i.iMtimeNsec);
    EXPECT_EQ(hmfsNodeData->i.iAtime, 1731565670);
    EXPECT_EQ(hmfsNodeData->i.iCtime, 1731565670);
    EXPECT_EQ(hmfsNodeData->i.iMtime, 1731565670);
}

/*
 * @tc.name: MkfsHmfsTest_w_001
 * @tc.desc: test for parameter w
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_w_001, TestSize.Level1)
{
    std::vector<char*> params;
    params.emplace_back(const_cast<char*>("/system/bin/mkfs.f2fs"));
    params.emplace_back(const_cast<char*>("-w 1024"));
    params.emplace_back(const_cast<char*>("/data/f2fsTest"));
    params.emplace_back(const_cast<char*>("15000000"));
    params.emplace_back(nullptr);
    EXPECT_EQ(0, ExecutableCmd(params[0], params.data()));

    params.clear();
    params.emplace_back(const_cast<char*>("/system/bin/mkfs.hmfs"));
    params.emplace_back(const_cast<char*>("-w 1024"));
    params.emplace_back(const_cast<char*>("/data/hmfsTest"));
    params.emplace_back(const_cast<char*>("15000000"));
    params.emplace_back(nullptr);
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);
    EXPECT_EQ(0, ExecutableCmd(params[0], params.data()));
}


/*
 * @tc.name: MkfsHmfsTest_w_002
 * @tc.desc: test for parameter w
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_w_002, TestSize.Level1)
{
    //f2fs
    std::vector<char*> params;
    params.emplace_back(const_cast<char*>("/system/bin/mkfs.f2fs"));
    params.emplace_back(const_cast<char*>("-w 1024"));
    params.emplace_back(const_cast<char*>("/data/f2fsTest"));
    params.emplace_back(const_cast<char*>("49152")); // 12 * 4096
    params.emplace_back(nullptr);
    EXPECT_NE(0, ExecutableCmd(params[0], params.data()));

    params.clear();
    params.emplace_back(const_cast<char*>("/system/bin/mkfs.f2fs"));
    params.emplace_back(const_cast<char*>("-w 1024"));
    params.emplace_back(const_cast<char*>("/data/f2fsTest"));
    params.emplace_back(const_cast<char*>("53248")); // 13 * 4096
    params.emplace_back(nullptr);
    EXPECT_EQ(0, ExecutableCmd(params[0], params.data()));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    EXPECT_TRUE(f2fsSuperBlock->sectionCount > 10);

    // hmfs
    params.clear();
    params.emplace_back(const_cast<char*>("/system/bin/mkfs.hmfs"));
    params.emplace_back(const_cast<char*>("-w 1024"));
    params.emplace_back(const_cast<char*>("/data/hmfsTest"));
    params.emplace_back(const_cast<char*>("49152")); // 12 * 4096
    params.emplace_back(nullptr);
    // Expected: (0) != (ExecutableCmd(params[0], params.data())), actual: 0 vs 0
    EXPECT_NE(0, ExecutableCmd(params[0], params.data()));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    params.clear();
    params.emplace_back(const_cast<char*>("/system/bin/mkfs.hmfs"));
    params.emplace_back(const_cast<char*>("-w 1024"));
    params.emplace_back(const_cast<char*>("/data/hmfsTest"));
    params.emplace_back(const_cast<char*>("53248")); // 13 * 4096
    params.emplace_back(nullptr);
    EXPECT_EQ(0, ExecutableCmd(params[0], params.data()));
    fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->sectionCount > 10);
}

/*
 * @tc.name: MkfsHmfsTest_w_003
 * @tc.desc: test for parameter w
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_w_003, TestSize.Level1)
{
    //f2fs
    std::vector<char*> params;
    params.emplace_back(const_cast<char*>("/system/bin/mkfs.f2fs"));
    params.emplace_back(const_cast<char*>("-w 2048"));
    params.emplace_back(const_cast<char*>("/data/f2fsTest"));
    params.emplace_back(const_cast<char*>("24576")); // 6 * 4096
    params.emplace_back(nullptr);
    EXPECT_NE(0, ExecutableCmd(params[0], params.data()));

    params.clear();
    params.emplace_back(const_cast<char*>("/system/bin/mkfs.f2fs"));
    params.emplace_back(const_cast<char*>("-w 2048"));
    params.emplace_back(const_cast<char*>("/data/f2fsTest"));
    params.emplace_back(const_cast<char*>("28672")); // 7 * 4096
    params.emplace_back(nullptr);
    EXPECT_EQ(0, ExecutableCmd(params[0], params.data()));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    EXPECT_TRUE(f2fsSuperBlock->sectionCount > 10);

    // hmfs
    params.clear();
    params.emplace_back(const_cast<char*>("/system/bin/mkfs.hmfs"));
    params.emplace_back(const_cast<char*>("-w 2048"));
    params.emplace_back(const_cast<char*>("/data/hmfsTest"));
    params.emplace_back(const_cast<char*>("24576")); // 6 * 4096
    params.emplace_back(nullptr);
    // Expected: (0) != (ExecutableCmd(params[0], params.data())), actual: 0 vs 0
    EXPECT_NE(0, ExecutableCmd(params[0], params.data()));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    params.clear();
    params.emplace_back(const_cast<char*>("/system/bin/mkfs.hmfs"));
    params.emplace_back(const_cast<char*>("-w 2048"));
    params.emplace_back(const_cast<char*>("/data/hmfsTest"));
    params.emplace_back(const_cast<char*>("28672")); // 7 * 4096
    params.emplace_back(nullptr);
    EXPECT_EQ(0, ExecutableCmd(params[0], params.data()));
    fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->sectionCount > 10);
}

/*
 * @tc.name: MkfsHmfsTest_z_000
 * @tc.desc: test for parameter z
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_z_000, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-z 0");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
}

/*
 * @tc.name: MkfsHmfsTest_z_001
 * @tc.desc: test for parameter z
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_z_001, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-z 1");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    EXPECT_TRUE(f2fsSuperBlock->sectionsPerZone == 1);
    EXPECT_TRUE(f2fsSuperBlock->sectionCount > 10);

    // hmfs
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->sectionsPerZone == 1);
    EXPECT_TRUE(hmfsSuperBlock->sectionCount > 10);
}

/*
 * @tc.name: MkfsHmfsTest_z_002
 * @tc.desc: test for parameter z
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_z_002, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-z 2");
    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/f2fsTest", f2fsSuperBlock);
    EXPECT_TRUE(f2fsSuperBlock->sectionsPerZone == 2);
    EXPECT_TRUE(f2fsSuperBlock->sectionCount > 10);

    EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
    bool fsckRes = ExecFsckBinaryAndCkeck("/data/hmfsTest");
    EXPECT_TRUE(fsckRes);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock("/data/hmfsTest", hmfsSuperBlock);
    EXPECT_TRUE(hmfsSuperBlock->sectionsPerZone == 2);
    EXPECT_TRUE(hmfsSuperBlock->sectionCount > 10);

    EXPECT_EQ(f2fsSuperBlock->sectionsPerZone, hmfsSuperBlock->sectionsPerZone);
    EXPECT_EQ(f2fsSuperBlock->sectionCount, hmfsSuperBlock->sectionCount);
}

/*
 * @tc.name: MkfsHmfsTest_z_003
 * @tc.desc: test for parameter z
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsSingleTest, Test_param_z_003, TestSize.Level1)
{
    std::vector<std::string> params;
    params.emplace_back("-z 6");
    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params, "/data/f2fsTest"));

    EXPECT_NE(0, MkfsHmfsSingleTest::ExecMkfsBinary("hmfs", params, "/data/hmfsTest"));
}

// /*
//  * @tc.name: MkfsHmfsTest_t_002
//  * @tc.desc: test for parameter t
//  * @tc.type: FUNC
//  */
// HWTEST_F(MkfsHmfsSingleTest, Test002, TestSize.Level1)
// {
//     std::string fileName("/data/hmfs_example.txt");
//     EXPECT_EQ(WriteFile(fileName), 0);
//     EXPECT_NE(ReadFile(fileName), "");

//     EXPECT_EQ(FAllocateFile(fileName), 0);
//     EXPECT_EQ(CheckDataIsZero(fileName), HmfsCode::SUCCESSED);
//     EXPECT_NE(ReadFile(fileName), "");

//     EXPECT_EQ(WriteFile(fileName), 0);
//     EXPECT_NE(ReadFile(fileName), "");

//     std::string hmfsName("/data/hmfsTest");

//     std::vector<std::string> params;
//     params.emplace_back("-a 0");
//     params.emplace_back(hmfsName);
//     EXPECT_EQ(0, MkfsHmfsSingleTest::ExecMkfsBinary("f2fs", params));

//     EXPECT_EQ(CheckDataIsZero(hmfsName), HmfsCode::FAILED);

//     struct stat statBuf{};
//     EXPECT_EQ(GetFileStat(hmfsName, &statBuf), 0);;
// }

} // namespace Hmfs
} // namespace OHOS